/**
 * forum zhanjung
 */
package com.junhong.forum.common;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.slf4j.Logger;

import com.junhong.auth.entity.RoleType;
import com.junhong.message.domain.MessageStatus;
import com.junhong.util.WebConfigUtil;

/**
 * @author zhanjung
 * 
 */
@Named
@ApplicationScoped
// TODO not sure if concurrencyManagement and lock will work with
// applicationScope
// @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
// @Lock(LockType.READ)
public class Constants {
	@Inject
	private Logger	logger;

	public Constants() {

	}

	public static final String	BLOCKQUOTETAG							= "<blockquote class='quoteBlockQuote'>";
	public static final String	BLANK									= "";
	public static final String	REPLYQUOTEWATERMARK						= "Please type here to reply ";
	public static final String	Yes										= "Yes";
	public static final String	No										= "No";
	public static final String	NEWUSERID								= "NEWUSERID";

	public static final String	CurrentUser								= "CURRENTUSER";
	public static final String	NavSuccess								= "SUCCESS";
	public static final String	NavLogin								= "LOGIN";
	public static final String	NAVCREATETHREAD							= "CREATETHREAD";
	public static final String	NAVCREATEREPLY							= "CREATEREPLY";
	public static final String	NavNull									= "";
	public static final String	Action_CREATE							= "CREATE";
	public static final String	Action_UPDATE							= "UPDATE";
	public static final String	Action_DELETE							= "DELETE";
	public static final String	Action_DASHBOARD						= "DASHBOARD";
	public static final String	Action_UNDASHBOARD						= "UNDASHBOARD";

	public static final String	POSTTHREAD_LOCATION						= "FROMPOSTTHREAD";
	public static final String	POSTREPLY_LOCATION						= "FROMPOSTREPLY";
	public static final String	LOGIN_LOCATION							= "LOGIN";
	public static final String	CURRENT_LOCATION						= "CURRENTLOCATION";
	public static final String	NavLogout								= "LOGOUT";
	// public static final String Belonging_Category = "BELONGINGCATEGORY";

	public static final String	USERGROUP_REGISTERED					= "REGISTERED";

	public static final String	PROFILE_TAB_BASICPROFILE				= "BASICPROFILE";
	public static final String	PROFILE_TAB_MESSAGES					= "MESSAGES";
	public static final String	PROFILE_TAB_CHANGE_PASSWORD				= "CHANGEPASSWORD";
	public static final String	PROFILE_TAB_MYPOST						= "MYPOST";
	public static final String	CURRENT_CATEGORY						= "currentCategory";
	public static final String	CURRENT_NEWSCATEGORY					= "currentNewsCategory";
	public static final String	BELONG_THREAD_ID						= "belongThreadId";
	public static final String	CURRENT_NEWS_INVIEW						= "currentNewsInView";
	public static final String	blockQuoteLine							= "----------";
	public static final String	blockQuoteStyle							= " 'background: #F7F7F7;border: 1px dashed green; clear: left;  margin-left: 0;   padding: 5px 10px;'";

	/*-----------------Message-------------------------*/

	public static String		Message_Inbox							= "Inbox";
	public static String		Message_Sent							= "Sent";
	public static String		Message_Archieve						= "Archieve";
	public static String		Message_Draft							= "Draft";
	public static final String	Message_Status_NEW						= MessageStatus.NEW.toString();
	public static final String	Number_Of_New_Message					= "NumberOfNewMessages";
	public static final String	Message_Bundle							= "resources.application";

	/*-----------------News-------------------------*/

	public static final String	Display_Type_Tab						= DisplayType.TAB.toString();
	public static final String	Display_Type_Regular					= DisplayType.REGULAR.toString();
	public static final String	NewsPoster_Role_Type					= RoleType.NEWSPOSTER.toString();

	/*-----------------webiste Index page Display Type-------------------------*/
	public static final String	Display_Type_Regular_Main_Index			= DisplayTypeMainPage.REGULAR.toString();
	public static final String	Display_Type_Mixed_Main_Index			= DisplayTypeMainPage.MIXED.toString();

	/*-----------------User-------------------------*/

	public static final String	USER_TAB_PROFILE_PIC					= "PROFILEPIC";
	public static final String	USER_TAB_BASICPROFILE					= "BASICPROFILE";
	public static final String	USER_TAB_CHANGEPWD						= "CHANGEPASSWORD";
	public static final String	USER_TAB_MYPOST							= "MYPOST";
	public static final String	USER_TAB_MYREPLY						= "MYREPLY";
	public static final String	USER_TAB_MYWATCHLIST					= "MYWATCHLIST";
	public static final String	USER_PROFILE_PIC_DIR					= WebConfigUtil.getProfilePicDestFoler();
	public static final String	PROFILE_PIC_WIDTH						= "PROFILE_PIC_WIDTH";
	public static final String	PROFILE_PIC_HEIGHT						= "PROFILE_PIC_HEIGHT";
	public static final String	PROFILE_PIC_FILE_EXT					= ".jpg";
	public static final String	PROFILE_PIC_DEFAULT_VALUE				= "dog.jpg";
	public static final String	USER_RESET_PWD_EMAIL_SUBJECT			= "USER_RESET_PASSWORD_SUBJECT";
	public static final String	USER_RESET_PWD_EMAIL_CONTENT_TEMPLATE	= "USER_RESET_PASSWORD_CONTENT_TEMPLATE";
	public static final String	VIEWPROFILE_SOUCE_4LAZYDATAMODEL		= "VIEWPROFILESOURCE";
	public static final String	VIEWPROFILE_USER_4LAZYDATAMODEL			= "VIEWPROFILEUSER";

	/** ------------Exception------------------------ */
	public static final String	NOTAUTHORIZEDACTION						= "NOTAUTHORIZEDACTION";

	/** ------------------global variable------------------------- */
	/*
	 * it is the category in which all its children categories are displaying in
	 * the listcategory page.
	 */
	public static final String	NAVIGATION_CATEGORY_ID					= "navCatId";

	/*
	 * it is the category in which all the thread are displaying in the
	 * viewthread page.
	 */
	public static final String	CATEGORY__THREAD_ID						= "ctgtThdId";
	public static final String	CATEGORY__NEWS_ID						= "ctgtNewsId";

	public static final String	Login_Page								= "/login.xhtml";

	/*
	 * this is the category matching to CATEGORY__THREAD_ID
	 */
	public static final String	BelongingCategory						= "belongingCategory";
	public static final String	BelonginNewsgCategory					= "belongingNewsCategory";

	public static final String	Blank_String							= "";

	/**
	 * -------------------loading the fields into cache-------------------------
	 * 
	 * 
	 * following logi is used to load all the fields in the map, which is used
	 * in EL
	 * 
	 * -------------------------------------------------------------------------
	 */
	// "cache" holding all public fields by it's field name:
	private Map<String, String>	nameToValueMap							= new HashMap<String, String>();

	/**
	 * Puts all public static fields into the resulting Map. Uses the name of
	 * the field as key to reference it's in the Map.
	 * 
	 * @return a Map of field names to field values of all public static fields
	 *         of this class
	 */
	@PostConstruct
	private void createNameToValueMap() {
		// init message inbox, draft etc depending on its locale
		this.Message_Inbox = Messages.getString(null, "Message_Inbox", null);
		this.Message_Draft = Messages.getString(null, "Message_Draft", null);
		this.Message_Sent = Messages.getString(null, "Message_Sent", null);
		this.Message_Archieve = Messages.getString(null, "Message_Archieve", null);
		logger.info("loading constants fields");
		Field[] publicFields = Constants.class.getFields();
		for (int i = 0; i < publicFields.length; i++) {
			Field field = publicFields[i];
			String name = field.getName();
			try {
				nameToValueMap.put(name, (String) field.get(null));
			} catch (Exception e) {
				logger.error("Initialization of Constants class failed!{}", e);
			}
		}

	}

	public Map<String, String> getNameToValueMap() {
		if (nameToValueMap.size() == 0) {
			createNameToValueMap();
		}
		return nameToValueMap;
	}

	public void setNameToValueMap(Map<String, String> nameToValueMap) {
		this.nameToValueMap = nameToValueMap;
	}

}
